package com.zy.qudadid.presenter;

import com.zy.qudadid.model.Res;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.network.Net;
import com.zy.qudadid.presenter.base.BasePresenterImp;
import com.zy.qudadid.ui.view.IndexGoView;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ninos on 2016/7/30.
 */
public class IndexGoPresenter extends BasePresenterImp<IndexGoView> {
    //    /api.php?c=infoOrderCar&a=user_startOrder&args=
    public void startOrder(String data) {
        Subscription subscription = Net.getService()
                .startOrder("infoOrderCar", "user_startOrder", data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.errorCost();
                    }

                    @Override
                    public void onNext(Res res) {
                        if (res.code == Const.OK) {
                            view.successCost();
                        } else {
                            view.errorCost();
                        }
                    }
                });

        addSubscription(subscription);
    }

}
